﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using thinger.VisionModels;
using thinger.VisitionDAL;

namespace thinger.VisionDemo
{
	//第一步：声明委托

	public delegate void OpenListDelegate(string frmName);

	public partial class FrmDataList : Form
	{
		private Random random = new Random();
		private List<overTime> t = new List<overTime>();
		private int okCount = 0;
		private int ngCount = 0;

		private string todayStr;
		private string yesterdayStr;

		public FrmDataList()
		{
			InitializeComponent();
			SetTimer(8, 0, t_Start);
			SetTimer(20, 0, t_End);
			SetTimer(8, 0, d_Start);
			SetTimer(20, 0, d_End);

			SetTimer(8, 0, pareto_start);
			SetTimer(20, 0, pareto_end);
			this.Load += FrmDataListLoad;
		}

		private void FrmDataListLoad(object sender, EventArgs e)
		{
			Mainpro.Instance.OnChangeRowRecive += OnChangeRowRecive;
			this.cmb_inquire.DataSource = new string[] { "良品", "不良品", "PASS", "搬运模组1", "搬运模组2", "全部信息" };
			this.cmb_inquire.SelectedIndex = 0;
			this.chc_cell_1.Checked = false;
			this.chc_cell_2.Checked = false;
			doChar1Hours();
			QueryProcess(this.t_Start.Value.ToString(), this.d_End.Value.ToString());
		}

		private void SetTimer(int hour, int minute, DateTimePicker dateTimePicker)
		{
			// 设置DateTimePicker为今天的指定时间
			//dateTimePicker = new DateTimePicker();
			//dateTimePicker.Format = DateTimePickerFormat.Custom;
			//dateTimePicker.CustomFormat = " "; // 使其不显示日期
			//dateTimePicker.ShowUpDown = true;
			//// 获取今天日期
			DateTime today = DateTime.Today;

			// 设置特定时间，例如15:30
			// 创建时间
			DateTime time = new DateTime(today.Year, today.Month, today.Day, hour, minute, 0);

			// 设置DateTimePicker的值
			dateTimePicker.Value = time;
		}

		public OpenListDelegate OpenList;

		private void button1_Click(object sender, EventArgs e)
		{
			OpenList("图形");
		}

		private void xkt_chrt()
		{
			chart1.Series[0].Points.Clear();
			chart1.Series[1].Points.Clear();
			this.chart1.Series[0].Color = Color.Green;
			this.chart1.Series[0].Name = "OK";
			this.chart1.Series[1].Color = Color.Red;
			this.chart1.Series[1].Name = "NG";
			if (t == null)
			{
				MessageBox.Show("暂时没有数据!");
				return;
			}
			if (t.Count < 1)
			{
				MessageBox.Show("暂时没有数据!");
				return;
			}

			for (int i = 0; i < t.Count; i++)
			{
				if ((t[i].okCount > 0) || (t[i].ngCount > 0))
				{
					this.chart1.Series[0].Points.AddXY(t[i].time, t[i].okCount);
					this.chart1.Series[1].Points.AddXY(t[i].time, t[i].ngCount);
				}
			}
		}

		private void doChar1Hours()
		{
			getTimes();
			QueryProcessA(d_Start.Value.ToString(), d_End.Value.ToString());
			doZhuProperties();
			xkt_chrt();
		}

		private void button1_Click_1(object sender, EventArgs e)
		{
			// 判断时间设置
			if (Hours == 0)
				MessageBox.Show("时间设置间隔小于1小时，请重新设置时间", "警告", MessageBoxButtons.OK);
			else if (Days != 0)
				MessageBox.Show("时间间隔大于24小时，请重新设置时间", "警告", MessageBoxButtons.OK);
			else
				doChar1Hours();
		}

		private void doTimeNow()
		{
			DateTimePicker dateTimePicker1 = new DateTimePicker();
			dateTimePicker1.Value = DateTime.Now; // 设置当前日期和时间
												  // 比较两个DateTimePicker的值
			if (dateTimePicker1.Value < d_Start.Value)
			{
				DateTime today = DateTime.Today; // 获取今天的日期
				DateTime yesterday = today.AddDays(-1); // 获取昨天的日期
														// dateTimePicker1.CustomFormat = "yyyy-MM-dd";
				yesterdayStr = yesterday.Year.ToString() + "/" + yesterday.Month.ToString() + "/" + yesterday.Day.ToString();
				yesterdayStr += " ";
				yesterdayStr += d_Start.Value.Hour.ToString() + ":" + d_Start.Value.Minute.ToString() + ":" + d_Start.Value.Second.ToString();
				todayStr = d_Start.Value.ToString();
			}
			else
			{
				yesterdayStr = d_Start.Value.ToString();
				todayStr = dateTimePicker1.Value.ToString();
			}
		}

		private void getTimes()
		{
			DateTime today = Convert.ToDateTime(d_Start.Value.ToString());
			DateTime gotoday = Convert.ToDateTime(d_End.Value.ToString());
			t = new List<overTime>();
			for (int i = 1; i < 100; i++)
			{
				DateTime tday = today.AddHours(i);
				t.Add(new overTime()
				{
					time = tday.Hour,
					ngCount = 0,
					okCount = 0,
				});
				int pp = gotoday.Hour - 1;
				if (tday.Hour == pp)
				{
					break;
				}
			}
		}

		private void doZhuProperties()
		{
			okCount = getDoQuery(d_Start.Value.ToString(), d_End.Value.ToString(), "1");
			ngCount = getDoQuery(d_Start.Value.ToString(), d_End.Value.ToString(), "0");
			double[] yValues = { okCount, ngCount };
			string[] xValues = { "良品", "不良" };
			this.chart3.Series[0].CustomProperties = "DoughnutRadius=60, PieLabelStyle=Disabled";
			this.chart3.Series[0].Label = "#PERCENT";
			this.chart3.Series[0]["PieLabelStyle"] = "Inside";

			// Change PieDrawingStyle to Default
			this.chart3.Series[0]["PieDrawingStyle"] = "Default";

			// Bind data
			this.chart3.Series[0].Points.DataBindXY(xValues, yValues);

			// Set custom labels with name and percentage
			for (int i = 0; i < xValues.Length; i++)
			{
				double percentage = (yValues[i] / yValues.Sum()) * 100;
				this.chart3.Series[0].Points[i].Label = $"{xValues[i]}: {percentage:F2}%";
			}
		}

		private int getDoQuery(string start, string end, string type)
		{
			//对开始时间和结束时间做判断

			DateTime t_start = Convert.ToDateTime(start);

			DateTime t_end = Convert.ToDateTime(end);

			if (t_start >= t_end)
			{
				return 0;
			}

			//SQL语句拼接

			StringBuilder sb = new StringBuilder();

			sb.Append("select * from product where createtime between '{0}' and '{1}'  and state='{2}'");

			string sql = string.Format(sb.ToString(), start, end, type);
			try
			{
				DataTable dataTable = MySqlHelper.GetDataTable(MySqlHelper.Conn, CommandType.Text, sql);

				return dataTable.Rows.Count;
			}
			catch (Exception)
			{
				return 0;
			}
		}

		private void QueryProcessA(string start, string end)
		{
			//对开始时间和结束时间做判断

			DateTime t_start = Convert.ToDateTime(start);
			DateTime t_end = Convert.ToDateTime(end);
			if (t_start >= t_end)
			{
				MessageBox.Show("开始时间必须小于结束时间", "查询提示");
				return;
			}

			//SQL语句拼接

			StringBuilder sb = new StringBuilder();
			sb.Append("SELECT HOUR(createtime) AS `hour`, (CASE WHEN state = '0' THEN '不良' WHEN state = '1' THEN '良' END) AS nametype, COUNT(id) AS 'count' FROM product WHERE(createtime BETWEEN '{0}' AND '{1}')  GROUP BY `hour`, `nametype`");
			string sql = string.Format(sb.ToString(), start, end);
			try
			{
				DataTable dataTable = MySqlHelper.GetDataTable(MySqlHelper.Conn, CommandType.Text, sql);
				//dataTable.Columns["LogTime"].ColumnName = "记录时间";
				if (dataTable.Rows.Count > 0)
				{
					foreach (DataRow row in dataTable.Rows)
					{
						for (int i = 0; i < t.Count; i++)
						{
							try
							{
								if (row["hour"].ToString() == t[i].time.ToString())
								{
									if (row["nametype"].ToString() == "良")
									{
										t[i].okCount = Convert.ToInt32(row["count"]);
									}
									if (row["nametype"].ToString() == "不良")
									{
										t[i].ngCount = Convert.ToInt32(row["count"]);
									}
								}
							}
							catch (Exception)
							{
							}
						}
					}
				}

				// MessageBox.Show("查询成功！" + sql);
			}
			catch (Exception ex)
			{
				LogRecord.WriteErrorLog("日志查询失败！" + ex.Message + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
				MessageBox.Show("查询失败！" + sql);
			}
		}

		private void GetcmbInquire()
		{
			columStr = "";
			findStr = "";
			if (chc_cell_2.Checked)
			{
				if (this.cmb_inquire.SelectedIndex == 0)
				{
					columStr = "state";
					findStr = "1";
				}
				if (this.cmb_inquire.SelectedIndex == 1)
				{
					columStr = "state";
					findStr = "0";
				}
				if (this.cmb_inquire.SelectedIndex == 2)
				{
					columStr = "workmode";
					findStr = "1";
				}
				if (this.cmb_inquire.SelectedIndex == 3)
				{
					columStr = "workmode";
					findStr = "2";
				}
				if (this.cmb_inquire.SelectedIndex == 4)
				{
					columStr = "";
					findStr = "";
				}
			}
			else
			{
				if (this.cmb_inquire.SelectedIndex == 0)
				{
					columStr = "state";
					findStr = "1";
				}
				if (this.cmb_inquire.SelectedIndex == 1)
				{
					columStr = "state";
					findStr = "0";
				}
				if (this.cmb_inquire.SelectedIndex == 2)
				{
					columStr = "ispass";
					findStr = "1";
				}
				if (this.cmb_inquire.SelectedIndex == 3)
				{
					columStr = "workmode";
					findStr = "1";
				}
				if (this.cmb_inquire.SelectedIndex == 4)
				{
					columStr = "workmode";
					findStr = "2";
				}
				if (this.cmb_inquire.SelectedIndex == 5)
				{
					columStr = "";
					findStr = "";
				}
			}
		}

		private string columStr;
		private string findStr;
		private DataTable data2 = new DataTable();

		private void QueryProcess(string start, string end)
		{
			//对开始时间和结束时间做判断
			try
			{
				DateTime t_start = Convert.ToDateTime(start);

				DateTime t_end = Convert.ToDateTime(end);

				if (t_start >= t_end)
				{
					MessageBox.Show("开始时间必须小于结束时间", "查询提示");
					return;
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
				return;
			}
			//--

			GetcmbInquire();
			if (chc_cell_2.Checked)
			{
				data2 = MySqlHelper.Get_CellInfo(start, end, columStr, findStr);
			}
			else
			{
				data2 = MySqlHelper.Get_Product(start, end, columStr, findStr, this.txt_coder.Text.Trim());
			}

			if (data2 == null || data2.Rows.Count < 1)
			{
				dgv_Log.DataSource = null;
				MessageBox.Show("未查询到数据！", "查询提示");
				return;
			}
			dgv_Log.DataSource = null;
			dgv_Log.DataSource = data2;

			if (chc_cell_2.Checked)
			{
				dgv_Log.Columns[4].Visible = false;
				dgv_Log.Columns[5].Visible = false;
			}
			else
			{
				//dgv_Log.Columns[7].Visible = false;
			}
			//dgv_Log.Columns.Clear();
			//dgv_Log.Rows.Clear();
			dgv_Log.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
			if (!chc_cell_2.Checked)
			{
				//dgv_Log.Columns[8].Width = 150;
			}
		}

		private void btn_updata_Click(object sender, EventArgs e)
		{
			doZhuProperties();
			if (MySqlHelper.Add_Report((ngCount + okCount).ToString(), ngCount.ToString(), okCount.ToString()))
			{
				MessageBox.Show("生产报告保存成功！", "报告保存");
			}
			else
			{
				MessageBox.Show("生产报告保存失败！", "报告失败");
			}
		}

		private void button5_Click(object sender, EventArgs e)
		{
			QueryProcess(this.t_Start.Value.ToString(), this.t_End.Value.ToString());
		}

		private void btn_OutExcel_Click(object sender, EventArgs e)
		{
			SaveFileDialog sfd = new SaveFileDialog();

			sfd.Filter = "XLS文件(*.xls)|*.xls|所有文件|*.*";

			sfd.FileName = "生产数据导出";

			sfd.DefaultExt = "xls";

			sfd.AddExtension = true;

			if (sfd.ShowDialog() == DialogResult.OK)
			{
				if (chc_cell_2.Checked)
				{
					if (NiceExcelSaveAndRead.SaveToExcelNew(sfd.FileName, this.dgv_Log))
					{
						MessageBox.Show("cellinfo导出成功！", "报表导出");
						LogRecord.WriteOperLog("cellinfo导出成功!" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
					}
					else
					{
						MessageBox.Show("cellinfo据导出失败！", "报表导出");
						LogRecord.WriteErrorLog("cellinfo导出失败!" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
					}
				}
				else
				{
					if (data2 == null || data2.Rows.Count < 1)
					{
						dgv_Log.DataSource = null;
						MessageBox.Show("没有数据,无法导出！", "提示");
						return;
					}

					if (NiceExcelSaveAndRead.SaveToExcelNew_dlist(sfd.FileName, this.dgv_Log))
					{
						MessageBox.Show("生产数据导出成功！", "报表导出");
						LogRecord.WriteOperLog("生产数据导出成功!" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
					}
					else
					{
						MessageBox.Show("生产数据导出失败！", "报表导出");
						LogRecord.WriteErrorLog("生产数据导出失败!" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
					}
				}
			}
		}

		private void chc_cell_2_CheckedChanged(object sender, EventArgs e)
		{
			if (chc_cell_2.Checked)
			{
				this.cmb_inquire.DataSource = new string[] { "良", "不良", "搬运模组1", "搬运模组2", "全部信息" };
				this.cmb_inquire.SelectedIndex = 0;
				this.txt_coder.Text = "";
				this.txt_coder.Enabled = false;
			}
			else
			{
				this.cmb_inquire.DataSource = new string[] { "良", "不良", "PASS", "搬运模组1", "搬运模组2", "全部信息" };
				this.cmb_inquire.SelectedIndex = 0;
				this.txt_coder.Enabled = true;
			}
		}

		public DateTime timeStart
		{
			get
			{
				DateTime Time1 = this.d_Start.Value;
				DateTime Time2 = this.d_End.Value;
				return Time1 >= Time2 ? Time2 : Time1;
			}
		}

		public DateTime timeEnd
		{
			get
			{
				DateTime Time1 = this.d_Start.Value;
				DateTime Time2 = this.d_End.Value;
				return Time1 > Time2 ? Time1 : Time2;
			}
		}

		public int Hours
		{
			get
			{
				TimeSpan ts1 = new TimeSpan(timeStart.Ticks);
				TimeSpan ts2 = new TimeSpan(timeEnd.Ticks);
				TimeSpan ts = ts1.Subtract(ts2).Duration();
				return ts.Hours;
			}
		}

		public int Days
		{
			get
			{
				TimeSpan ts1 = new TimeSpan(timeStart.Ticks);
				TimeSpan ts2 = new TimeSpan(timeEnd.Ticks);
				TimeSpan ts = ts1.Subtract(ts2).Duration();
				return ts.Days;
			}
		}

		private void OnChangeRowRecive(object sender, int e)
		{
			if (this.InvokeRequired)
			{
				this.Invoke(new Action<object, int>(OnChangeRowRecive), sender, e);
			}
			else
			{
				if (!chc_cell_2.Checked || data2 == null)
				{
					return;
				}
				index = index + e;
				if (index < 0)
				{
					index = 0;
				}
				else if (index > dgv_Log.Rows.Count - 1)
				{
					index = dgv_Log.Rows.Count - 1;
				}
				if (index >= 0 && index < dgv_Log.Rows.Count)
				{
					dgv_Log.ClearSelection(); // 清除当前的任何选择
					dgv_Log.Rows[index].Selected = true; // 设置特定行为选中状态

					DataGridViewRow row = dgv_Log.Rows[index];
					if (!File.Exists(row.Cells[4].Value.ToString()))
					{
						MessageBox.Show($"文件不存在！路径:{row.Cells[4].Value}");
						return;
					}
					if (!File.Exists(row.Cells[5].Value.ToString()))
					{
						MessageBox.Show($"文件不存在！路径:{row.Cells[5].Value}");
						return;
					}

					Mainpro.Instance.GetRow(new ImgMsg() { file = row.Cells[4].Value.ToString(), filec = row.Cells[5].Value.ToString(), cellid = row.Cells[3].Value.ToString() });
				}
			}
		}

		private static int index;

		private void dgv_Log_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
		{
			if (!chc_cell_2.Checked || data2 == null)
			{
				return;
			}
			if (e.RowIndex >= 0) // 确保点击的不是列头
			{
				// 获取双击的行
				DataGridViewRow row = dgv_Log.Rows[e.RowIndex];

				// 获取双击的单元格数据
				object cellValue = row.Cells[e.ColumnIndex].Value;

				// 在这里处理你的数据，例如显示、编辑或其他操作
				// MessageBox.Show($"双击的行数据:{cellValue} 列数:{e.ColumnIndex} 4:{row.Cells[4].Value}   5:{row.Cells[5].Value}");

				if (!File.Exists(row.Cells[4].Value.ToString()))
				{
					MessageBox.Show($"文件不存在！路径:{row.Cells[4].Value}");
					return;
				}
				if (!File.Exists(row.Cells[5].Value.ToString()))
				{
					MessageBox.Show($"文件不存在！路径:{row.Cells[5].Value}");
					return;
				}

				FrmImg frm = new FrmImg(new ImgMsg() { file = row.Cells[4].Value.ToString(), filec = row.Cells[5].Value.ToString(), cellid = row.Cells[3].Value.ToString() });
				frm.StartPosition = FormStartPosition.CenterScreen;
				frm.TopLevel = true;
				frm.BringToFront();
				frm.Show();
			}
		}

		/// <summary>
		/// set良率推移图
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void setBtn_Click(object sender, EventArgs e)
		{
			// 查询所有数据
			// 起始时间
			DateTime _time1 = Convert.ToDateTime(this.set_start.Value.ToString());

			// 结束时间
			DateTime _time2 = Convert.ToDateTime(this.set_end.Value.ToString());

			if (_time1 >= _time2)
			{
				MessageBox.Show("结束时间不能小于开始时间", "警告", MessageBoxButtons.OK);
			}

			// 查询良率
		}

		/// <summary>
		/// 不良项目柏拉图
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void paretoBtn_Click(object sender, EventArgs e)
		{
			try
			{
				// 查询所有数据
				// 起始时间
				DateTime _time1 = Convert.ToDateTime(this.pareto_start.Value.ToString());

				// 结束时间
				DateTime _time2 = Convert.ToDateTime(this.pareto_end.Value.ToString());

				if (_time1 >= _time2)
				{
					MessageBox.Show("结束时间不能小于开始时间", "警告", MessageBoxButtons.OK);
					return;
				}

				//if (this.platoComb.Text == "")
				//{
				//	MessageBox.Show("请先选择维度", "警告", MessageBoxButtons.OK);
				//}

				var piciStr = "";
				if (this.pici_tb.Text.Trim() != "")
				{
					piciStr = $" and damaPici = '{this.pici_tb.Text.Trim()}'";
				}

				// 查询时间范围内所有ng 内容
				var sql = $@"select * from cellinfo_detail
							where createtime between '{_time1}' and '{_time2}'
								and state = '0'
								{piciStr}
								and rectErrs <> ''";

				DataTable dataTable = MySqlHelper.GetDataTable(MySqlHelper.Conn, CommandType.Text, sql);

				if (dataTable == null || dataTable.Rows?.Count <= 0)
				{
					MessageBox.Show("暂无数据", "查询提示");

					return;
				}

				var sql2 = $@"SELECT DISTINCT(SUBSTRING_INDEX(SUBSTRING_INDEX(a.col,',',b.help_topic_id + 1),',',-1)) as errStr
							from (select group_concat(distinct `rectErrs`) as col
											from `cellinfo_detail` as aa
											where createtime between '2024-12-01' and '2025-12-01'
											and state = '0'
											and rectErrs <> '' ) as a
							join mysql.help_topic as b
							on b.help_topic_id < (CHAR_LENGTH(a.col) - CHAR_LENGTH(replace(a.col,',','')) + 1)";

				DataTable dataTable2 = MySqlHelper.GetDataTable(MySqlHelper.Conn, CommandType.Text, sql2);

				List<string> errStr = new List<string>();

				if (dataTable2?.Rows?.Count > 0)
				{
					foreach (DataRow item in dataTable2.Rows)
					{
						errStr.Add(item["errStr"].ToString());
					}
				}

				List<PlatoChartData> dataList = new List<PlatoChartData>();

				// 将数据切换到列表中
				foreach (DataRow row in dataTable.Rows)
				{
					dataList.Add(new PlatoChartData()
					{
						lotid = row["lotid"] == null ? "" : row["lotid"].ToString(),
						cellid = row["cellid"] == null ? "" : row["cellid"].ToString(),
						createtime = row["createtime"] == null ? DateTime.MinValue : Convert.ToDateTime(row["createtime"]),
						damaPici = row["damaPici"] == null ? "" : row["damaPici"].ToString(),
						facemode = row["facemode"] == null ? "" : row["facemode"].ToString(),
						rectErrs = row["rectErrs"] == null ? "" : row["rectErrs"].ToString(),
					});
				}

				if (dataList?.Count > 0)
				{
					Dictionary<string, int> paretoData = new Dictionary<string, int>();

					this.paretoChart.Series[0].Points.Clear();
					this.paretoChart.Series[0].Label = string.Empty;
					this.paretoChart.Series[1].Points.Clear();
					this.paretoChart.Series[0].IsValueShownAsLabel = true;//显示标签

					this.paretoChart.ChartAreas[0].AxisY2.LabelStyle.Format = "0%";//格式化，为了显示百分号
					this.paretoChart.ChartAreas[0].AxisY2.Interval = 0.2;//设置刻度间隔为20%
					this.paretoChart.ChartAreas[0].AxisX.Title = "不良项";
					this.paretoChart.ChartAreas[0].AxisY.Title = "数量";
					this.paretoChart.ChartAreas[0].AxisY2.Title = "百分比";

					this.paretoChart.Series[1].BorderWidth = 2;

					//标记点边框颜色
					this.paretoChart.Series[1].MarkerBorderColor = Color.Blue;
					//标记点边框大小
					this.paretoChart.Series[1].MarkerBorderWidth = 3; //chart1.;// Xaxis
																	  //标记点中心颜色
					this.paretoChart.Series[1].MarkerColor = Color.White;//AxisColor
																		 //标记点大小
					this.paretoChart.Series[1].MarkerSize = 8;
					//标记点类型
					this.paretoChart.Series[1].MarkerStyle = MarkerStyle.Circle;

					//将文字移到外侧
					this.paretoChart.Series[1]["PieLabelStyle"] = "Outside";

					var allCount = 0;
					foreach (var err in errStr)
					{
						var count = dataList.Where(w => w.rectErrs.Contains(err)).Count();
						paretoData.Add(err, count);
						allCount += count;
					}

					var orderData = paretoData.OrderByDescending(o => o.Value);

					int index = 0;
					double summa = 0.0;
					foreach (var order in orderData)
					{
						this.paretoChart.Series[0].Points.AddXY(order.Key, order.Value);
						this.paretoChart.Series[0].Points[index].Label = $"数量：{order.Value} 百分比：{Math.Round(Convert.ToDouble(order.Value) / Convert.ToDouble(allCount), 2) * 100}%";

						summa += Math.Round(Convert.ToDouble(order.Value) / Convert.ToDouble(allCount), 2);
						this.paretoChart.Series[1].Points.AddXY(order.Key, $"{summa}");

						//需要提示的信息
						this.paretoChart.Series[1].ToolTip = "累积占比：#VAL\n";

						index++;
					}

					// 添加折线，添加百分比
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.ToString());
			}
		}
	}
}